 package com.stork.sms.activity;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

import com.navdrawer.SimpleSideDrawer;
import com.stork.sms.R;
import com.stork.sms.adapter.GridMenuAdapter;
import com.stork.sms.model.GridMenu;
public class GridHomeMenuActivity extends Activity {
    private GridView menuGridView;
    private Toast toast;
    private SimpleSideDrawer ssdrawer;
    TextView set;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_grid_home_menu);
//		ActionBar actionBar = getActionBar();
//		actionBar.setTitle("Student Management System");
//		actionBar.setDisplayHomeAsUpEnabled(true);
		set=(TextView)findViewById(R.id.settings);
		ssdrawer=new SimpleSideDrawer(this);
		ssdrawer.setRightBehindContentView(R.layout.drawer);
//		set.setOnClickListener(new OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
//			Toast.makeText(getApplicationContext(), "Welcome",Toast.LENGTH_SHORT).show();	
//			}
//		});
		intializeView();
	}

	private void intializeView(){
		int menuName[] = { R.string.grid_menu_attendance,
				R.string.grid_menu_exam_schedule,
				R.string.grid_menu_exam_marks, R.string.grid_menu_lms,
				R.string.grid_menu_fees_details, R.string.grid_menu_calendar,
				R.string.grid_menu_profile, R.string.grid_menu_contact_us };

		int menuImageId[] = { R.drawable.menu_attendance,
				R.drawable.menu_exam_schedule, R.drawable.menu_exam_result,
				R.drawable.menu_lms, R.drawable.menu_fees,
				R.drawable.menu_calendar, R.drawable.menu_profile,
				R.drawable.menu_contact_us };
		
		List<GridMenu> menuList = new ArrayList<GridMenu>();
		for(int i=0;i<menuName.length;i++){
			GridMenu gridMenu=new GridMenu(getString(menuName[i]), menuImageId[i]);
			menuList.add(gridMenu);
		}
		
		menuGridView=(GridView)findViewById(R.id.menurGidView);
		
		GridMenuAdapter gridMenuAdapter=new GridMenuAdapter(this, menuList);
		menuGridView.setAdapter(gridMenuAdapter);
		
		menuGridView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
				if (position == 0) {
//					displayToast(getString(R.string.welcome_Attendence));
					Intent att=new Intent(GridHomeMenuActivity.this,AttendenceActivity.class);
					startActivity(att);
				} else if (position == 1) {
					displayToast(getString(R.string.future_under_development));
					displayToast(getString(R.string.grid_menu_exam_schedule));
					
					Intent ExamList=new Intent(GridHomeMenuActivity.this, ExamList.class);
					startActivity(ExamList);
				} else if (position == 2) {
					displayToast(getString(R.string.future_under_development));
					Intent MarkList=new Intent(GridHomeMenuActivity.this, MarkList.class);
					startActivity(MarkList);
					//displayToast(getString(R.string.grid_menu_exam_marks));
				} else if (position == 3) {
					displayToast(getString(R.string.future_under_development));
					displayToast(getString(R.string.grid_menu_lms));
				} else if (position == 4) {
					//displayToast(getString(R.string.grid_menu_fees_details));
					Intent fees=new Intent(GridHomeMenuActivity.this,FeesActivity.class);
					startActivity(fees);
				}/* else if (position == 5) {
					Intent calendarIntent=new Intent(GridHomeMenuActivity.this,CalendarActivity.class);
					startActivity(calendarIntent);
				}*/ else if (position == 6) {
					//displayToast(getString(R.string.welcome_Profile));
					Intent profile=new Intent(GridHomeMenuActivity.this,StudentProfileActivity.class);
					startActivity(profile);
				} else if (position == 7) {
//					displayToast(getString(R.string.future_under_development));
					Intent contactus=new Intent(GridHomeMenuActivity.this, Contactus.class);
					startActivity(contactus);
				}
				
			}
		});
		
	}

	
	private void displayToast(String msg){
		if(toast!=null){
			toast.cancel();
		}
		toast=Toast.makeText(this, msg,Toast.LENGTH_SHORT);
		toast.show();
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch(item.getItemId()){
		case R.id.action_settings:
			ssdrawer.toggleRightDrawer();
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
